#include <vector>
#include <deque>
#include <list>
#include <iostream>

using std::cout;
using std::endl;
using std::vector;
using std::list;
using std::deque;

template <class Container>
void display(const Container & c)
{
    auto it = c.begin();
    while(it != c.end()) {
        cout << *it << " ";
        ++it;
    }
    cout << endl;
}

void test0()
{
    vector<int> numbers{5, 1, 2, 3, 4};
    display(numbers);

    numbers.push_back(6);
    //vector不支持push_front操作
    //numbers.push_front(1);

    //支持随机访问迭代器
    auto it = numbers.begin();
    cout << "*(it + 3):" << *(it + 3) << endl;

    vector<int>::iterator it2 = numbers.begin();
}

void test1()
{
    cout << "\n test1(): " << endl;
    deque<int> numbers{5, 1, 2, 3, 4};
    numbers.push_back(6);
    //deque支持push_front操作
    numbers.push_front(1);
    display(numbers);

    //支持随机访问迭代器
    auto it = numbers.begin();
    cout << "*(it + 3):" << *(it + 3) << endl;
}

void test2()
{
    cout << "\n test2(): " << endl;
    list<int> numbers{5, 1, 2, 3, 4};
    numbers.push_back(6);
    //list支持push_front操作
    numbers.push_front(1);
    display(numbers);

    //list不支持随机访问迭代器
    auto it = numbers.begin();
    //cout << "*(it + 3):" << *(it + 3) << endl;
    //list支持双向访问迭代器
    it++;//只能一个一个向前向后遍历
    cout << "*it:" << *it << endl;
    --it;
    cout << "*it:" << *it << endl;

}

int main()
{
    test0();
    test1();
    test2();

    return 0;
}

